package study;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @Author 刘伟涛
 * @Date 2023/12/11 17:24
 **/
public class 输入年月日输出天数 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("请输入年");
            int year = scanner.nextInt();
            while (year < 0) {
                System.out.println("请输入有效数字");
                System.out.println("请输入年");
                year = scanner.nextInt();
            }
            System.out.println("请输入月");
            int month = scanner.nextInt();
            while (month <= 0 || month > 12) {
                System.out.println("请输入有效数字");
                System.out.println("请输入月");
                month = scanner.nextInt();
            }
            System.out.println("请输入日");
            int day = scanner.nextInt();
            while (!validate(year, month, day)) {
                System.out.println("请输入有效数字");
                System.out.println("请输入日");
                day = scanner.nextInt();
            }
            //总天数
            int sumDays = 0;
            List<Integer> integers = Arrays.asList(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
            //判断闰年，修改二月29天
            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
                integers.set(1, 29);
            }
            for (int i = 0; i < month - 1; i++) {
                sumDays += integers.get(i);
            }
            sumDays += day;
            System.out.println(sumDays);

        }
    }

    static Boolean validate(int year, int month, int day) {
        List<Integer> bigMonths = Arrays.asList(1, 3, 5, 7, 8, 10, 12);
        List<Integer> smallMonths = Arrays.asList(4, 6, 9, 11);
        if (day <= 0) {
            return false;
        }
        if (bigMonths.contains(month) && day <= 31) {
            return true;
        }
        if (smallMonths.contains(month) && day < 31) {
            return true;
        }
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            return day <= 29;
        } else {
            return day < 29;
        }
    }
}
